package gov.ccswj.modules.apibusiness.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.mysql.fabric.xmlrpc.base.Array;

import gov.ccswj.modules.api.annotation.AuthIgnore;
import gov.ccswj.modules.apibusiness.service.ForeginManagementService;
import gov.ccswj.modules.apibusiness.service.PreciseInvestmentService;
import gov.ccswj.modules.apibusiness.utils.ApiR;

/**
 * @author KY.Cheng
 * 大屏接口
 */
@RestController
@RequestMapping("/api/foregin/trade")
public class ForeginManagementController {

	@Autowired
	private PreciseInvestmentService preciseInvestmentService;
	@Autowired
	private ForeginManagementService foreginManagementService;
	/**
	 * 2.1.1政策法规
	 */
	
	
	
	
	@AuthIgnore
	@GetMapping("/policy")
	public ApiR info(Integer s,Integer n,String policyType, HttpServletResponse response) {
		
		if(s==null || n==null || policyType==null){
			return ApiR.ok().put("status", 101).put("data", "当前的参数无效或者还未生效中");
		}
		
		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		
		List<Map<String, Object>> list = foreginManagementService.policy(s,n,policyType);
			
		if(list.size()==0 || list==null){
			return ApiR.ok().put("data", list);
		}
		int total =foreginManagementService.count("b_l_foreign_policy");
		
		
		return ApiR.ok().put("total", total).put("data", list);
	}
	
	/**
	 * 行业产业链
	 * 
	 * @param response
	 * @return
	 */
	@AuthIgnore
	@GetMapping("/industry")
	public ApiR industry(String industryType,Integer s,Integer n,HttpServletResponse response) {
		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");

		if(s==null || n==null || industryType==null){
			return ApiR.ok().put("message","参数不能为空");
		}
		List<Map<String, Object>> list = preciseInvestmentService.industry();
		if(industryType.equals("1")){
			
		}else{
			return ApiR.ok().put("data", list);
		}
		
		

		if(list.size()==0 || list==null){
			return ApiR.ok().put("data", list);
		}
		Map<String, Object> map = new HashMap<String, Object>();

		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> map1 = new HashMap<String, Object>();
			map1.put("name", list.get(i).get("industry_name").toString());
			map1.put("child", list.get(i).get("child_id").toString());
			map.put(switchWord(i), map1);
		}
		
		Map<String, Object> link1 = new HashMap<String, Object>();
		link1.put("source", "能源电力");
		link1.put("target", "新能源");
		Map<String, Object> link2 = new HashMap<String, Object>();
		link2.put("source", "能源电力");
		link2.put("target", "石油");
		Map<String, Object> link3 = new HashMap<String, Object>();
		link3.put("source", "能源电力");
		link3.put("target", "太阳能");
		Map<String, Object> link4 = new HashMap<String, Object>();
		link4.put("source", "能源电力");
		link4.put("target", "煤炭");

		List<Map<String, Object>> links = new ArrayList<Map<String,Object>>() ;
		links.add(link1);
		links.add(link2);
		links.add(link3);
		links.add(link4);
		
		return ApiR.ok().put("data", map).put("links", links);

	}
	public String switchWord(int i){
		switch(i){
		case(0): return "one";
		case(1): return "two";
		case(2): return "three";

		default : return "";
		}
	}

	
	/**
	 * 2.1.3进出口交易额增降幅度（折线图）
	 */
	@AuthIgnore
	@GetMapping("/inoutyear")
	public ApiR inout1(HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		List<Map<String, Object>> list2017 = foreginManagementService.inoutyear("2017");
		List<Map<String, Object>> list2016 = foreginManagementService.inoutyear("2016");
			
		if(list2017.size()==0 ||list2016.size()==0){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		List<String> xlist=new ArrayList<>();
		List<String> list17=new ArrayList<>();
		List<String> list16=new ArrayList<>();
		for(Map<String, Object> map: list2017){
			xlist.add(map.get("month").toString());
		}
		
		for(Map<String, Object> map: list2017){
			list17.add(map.get("data").toString());
		}
		for(Map<String, Object> map: list2016){
			list16.add(map.get("data").toString());
		}
		
		String[] strs=new String[] {"去年同期","当年同期"};
		Map<String,Object> map1= new HashMap<String,Object>();
		Map<String,Object> map2= new HashMap<String,Object>();
		
		map1.put("name", strs[0]);
		map1.put("data", list16);
		map2.put("data", list17);
		map2.put("name", strs[1]);
	
		List<Map<String, Object>> list = new ArrayList<>();
		list.add(map1);
		list.add(map2);
		
		return ApiR.ok().put("data", strs).put("x", xlist).put("y", list);
	}
	
	
	/**
	 *2.1.4 进出口交易额的国家分析（柱状图）
	 */
	@AuthIgnore
	@GetMapping("/inoutcountry")
	public ApiR inout2(HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		List<Map<String, Object>> list = foreginManagementService.inoutcountry("2017");
			
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		List<String> xlist=new ArrayList<>();
		List<String> ylist=new ArrayList<>();
		for(Map<String, Object> map: list){
			xlist.add(map.get("country").toString());
		}
		
		for(Map<String, Object> map: list){
			ylist.add(map.get("outdata").toString());
		}
		
	
		Map<String, Object> map = new HashMap<>();
		map.put("x", xlist);
		map.put("y",ylist);
		
		return ApiR.ok().put("data", map);
	}
	
	/**
	 *2.1.4 进出口交易额的国家分析（柱状图）
	 */
	@AuthIgnore
	@GetMapping("/inoutcountrycount")
	public ApiR inout3(HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		List<Map<String, Object>> list = foreginManagementService.inoutcountry("2017");
			
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		List<String> xlist=new ArrayList<>();
		Map<String, Object> mapy1 = new HashMap<>();
		Map<String, Object> mapy2 = new HashMap<>();
		for(Map<String, Object> map: list){
			xlist.add(map.get("country").toString());
		}
		
		
		for(Map<String, Object> map: list){
			mapy1.put("value", map.get("outdata").toString());
			mapy1.put("name", "出口");
			mapy2.put("value", map.get("indata").toString());
			mapy2.put("name", "进口");
		}
		
		List<Object> y=new ArrayList<>();
		y.add(mapy1);
		y.add(mapy2);
		
		String[] strs=new String[] {"进口","出口"};
		
		Map<String, Object> map = new HashMap<>();
		map.put("name", strs);
		map.put("x", xlist);
		map.put("y", y);
		
		return ApiR.ok().put("data", map);
	}
	
	/**
	 *2.2 项目
	 */
	@AuthIgnore
	@GetMapping("/project")
	public ApiR project(Integer s,Integer n ,HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		if(s==null || n==null){
			return ApiR.ok().put("message","参数不能为空");
		}
		
		List<Map<String, Object>> list = foreginManagementService.project(s,n);

		int total =foreginManagementService.count("b_l_project_info");
		
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		
		Map<String, Object> map = new HashMap<>();
		
		return ApiR.ok().put("total", total).put("data", list);
	}
	
	
	/**
	 *2.2 项目xiangqing
	 */
	@AuthIgnore
	@GetMapping("/projectid")
	public ApiR projectid(Integer id,HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		if(id==null){
			return ApiR.ok().put("message","参数不能为空");
		}
		
		List<Map<String, Object>> list = foreginManagementService.projectid(id);

		
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		
		Map<String, Object> map = new HashMap<>();
		map.put("baseMsg", list.get(0));
		
		Map<String, Object> company = new HashMap<>();
		company.put("name", "");
		company.put("contacts", "");
		company.put("address", "");
		company.put("phone", "");
		company.put("website", "");
		company.put("cell", "");
		
		
		return ApiR.ok().put("baseMsg", map).put("company", company);
	}
	
	/**
	 *2.5.2 进出口贸易知识库
	 */
	@AuthIgnore
	@GetMapping("/knowledge/inout")
	public ApiR knowledge(String searchKey,String area, Integer industry,Integer message,Integer s,Integer n,HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		if(s==null || n==null){
			return ApiR.ok().put("message","参数不能为空");
		}
		List<Map<String, Object>> list=new ArrayList();
		if(area !=null && !area.equals("长春")){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		if(industry ==null){
			 list = foreginManagementService.knowledgeall(searchKey,message,s,n);

		}else{
			list = foreginManagementService.knowledge(searchKey,industry,message,s,n);
		}
		 

		
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		
		Map<String, Object> map = new HashMap<>();
		map.put("baseMsg", list.get(0));
		
		return ApiR.ok().put("data", list);
	}
	
/**
 * ******************************************************************************	
 */
	/**
	 *商机推荐 文章
	 */
	@AuthIgnore
	@GetMapping("/article")
	public ApiR article(String text,Integer s ,Integer n,HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		if(s==null || n==null){
			return ApiR.ok().put("message","参数不能为空");
		}
		
		List<Map<String, Object>> list = foreginManagementService.article(text,s,n);

		int total =foreginManagementService.count("b_l_business_article");
		
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		
		Map<String, Object> map = new HashMap<>();
		
		return ApiR.ok().put("total", total).put("data", list);
	}
	
	/**
	 *商机推荐 文章 详情
	 */
	@AuthIgnore
	@GetMapping("/articleid")
	public ApiR articleid(Integer id,HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		if(id==null ){
			return ApiR.ok().put("message","参数不能为空");
		}
		
		List<Map<String, Object>> list = foreginManagementService.articleid(id);

		
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		
		Map<String, Object> map = new HashMap<>();
		
		return ApiR.ok().put("data", list);
	}
	
	/**
	 *项目列表 文章
	 */
	@AuthIgnore
	@GetMapping("/projectlist")
	public ApiR projectlist(String text,Integer s ,Integer n,HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		if(s==null || n==null){
			return ApiR.ok().put("message","参数不能为空");
		}
		
		List<Map<String, Object>> list = foreginManagementService.projectlist(text,s,n);

		int total =foreginManagementService.count("b_l_business_projectinfo");
		
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		Map<String, Object> map = new HashMap<>();
		
		return ApiR.ok().put("total", total).put("data", list);
	}
	
	/**
	 *x项目 详情
	 */
	@AuthIgnore
	@GetMapping("/projectlistid")
	public ApiR projectlistid(Integer id,HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		if(id==null ){
			return ApiR.ok().put("message","参数不能为空");
		}
		
		List<Map<String, Object>> list = foreginManagementService.projectlistid(id);

		
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		
		Map<String, Object> map = new HashMap<>();
		
		return ApiR.ok().put("data", list);
	}
	
	/**
	 *供求信息文章
	 */
	@AuthIgnore
	@GetMapping("/supplydemand")
	public ApiR supplydemand(String text,Integer s ,Integer n,HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		if(s==null || n==null){
			return ApiR.ok().put("message","参数不能为空");
		}
		
		List<Map<String, Object>> list = foreginManagementService.supplydemand(text,s,n);

		int total =foreginManagementService.count("b_l_business_supply_demand");
		
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		
		Map<String, Object> map = new HashMap<>();
		
		return ApiR.ok().put("total", total).put("data", list);
	}
	
	/**
	 *供求信息 详情
	 */
	@AuthIgnore
	@GetMapping("/supplydemandid")
	public ApiR supplydemandid(Integer id,HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		if(id==null ){
			return ApiR.ok().put("message","参数不能为空");
		}
		
		List<Map<String, Object>> list = foreginManagementService.supplydemandid(id);

		
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		Map<String, Object> company = new HashMap<>();
		company.put("name", "");
		company.put("contacts", "");
		company.put("address", "");
		company.put("phone", "");
		company.put("website", "");
		company.put("cell", "");
		
		return ApiR.ok().put("baseMsg", list).put("company", company);
	}
	
	/**
	 *行业发展文章
	 */
	@AuthIgnore
	@GetMapping("/industryarticle")
	public ApiR industryarticle(Integer s ,Integer n,HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		if(s==null || n==null){
			return ApiR.ok().put("message","参数不能为空");
		}
		
		List<Map<String, Object>> list = foreginManagementService.industryarticle(s,n);

		int total =foreginManagementService.count("b_l_industry_article");
		
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		
		Map<String, Object> map = new HashMap<>();
		
		return ApiR.ok().put("total", total).put("data", list);
	}
	
	/**
	 *行业发展 详情
	 */
	@AuthIgnore
	@GetMapping("/industryarticleid")
	public ApiR industryarticleid(Integer id,HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		if(id==null ){
			return ApiR.ok().put("message","参数不能为空");
		}
		
		List<Map<String, Object>> list = foreginManagementService.industryarticleid(id);

		
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		
		Map<String, Object> map = new HashMap<>();
		
		return ApiR.ok().put("data", list);
	}
	
	
	/**
	 *贸易风险文章
	 */
	@AuthIgnore
	@GetMapping("/traderisk")
	public ApiR traderisk(String text,Integer s ,Integer n,HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		if(s==null || n==null){
			return ApiR.ok().put("message","参数不能为空");
		}
		
		List<Map<String, Object>> list = foreginManagementService.traderisk(text,s,n);

		int total =foreginManagementService.count("b_l_traderisk_article");
		
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		
		Map<String, Object> map = new HashMap<>();
		
		return ApiR.ok().put("total", total).put("data", list);
	}
	
	/**
	 *供求信息 详情
	 */
	@AuthIgnore
	@GetMapping("/traderiskid")
	public ApiR traderiskid(Integer id,HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		if(id==null ){
			return ApiR.ok().put("message","参数不能为空");
		}
		
		List<Map<String, Object>> list = foreginManagementService.traderiskid(id);

		
		if(list.size()==0 ){
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		
		Map<String, Object> map = new HashMap<>();
		
		return ApiR.ok().put("data", list);
	}
	
	/**
	 *2.5.5.1 信息统计、数据统计
	 */
	@AuthIgnore
	@GetMapping("/infoanalysis")
	public ApiR infoanalysis(HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		
			
		
		Map<String, Object> chainData = new HashMap<>();
		chainData.put("inOutCompany", "");
		chainData.put("inCompany", "");
		chainData.put("inKeyCompany", "");
		chainData.put("inNewCompany", "");
		chainData.put("outCompany", "");
		chainData.put("outKeyCompany", "");
		chainData.put("outNewCompany", "");
		
		Map<String, Object> treeInData  = new HashMap<>();
		Map<String, Object> treeInData1  = new HashMap<>();
		treeInData1.put("name", "肉及杂碎");
		
		treeInData.put("name", "出口交易");
		treeInData.put("children",treeInData1 );
		
		
		Map<String, Object> treeOutData  = new HashMap<>();
		Map<String, Object> treeOutData1  = new HashMap<>();
		treeOutData1.put("name", "肉及杂碎");
		
		treeOutData.put("name", "出口交易");
		treeOutData.put("children",treeInData1 );
		
		return ApiR.ok().put("chainData", chainData).put("treeOutData", treeOutData).put("treeInData", treeInData);
	}
	
	
	
	
	
	
	/**
	 *进口今年与去年走势对比
	 */
	@AuthIgnore
	@GetMapping("/inyear")
	public ApiR inyear(HttpServletResponse response) {
		


		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		List<Map<String, Object>> list2017 = foreginManagementService.inyear("2017");
		List<Map<String, Object>> list2016 = foreginManagementService.inyear("2016");
	
		
		List<String> xlist=new ArrayList<>();
		List<String> y1=new ArrayList<>();
		List<String> y2=new ArrayList<>();
		Map<String, Object> mapy1 = new HashMap<>();
		Map<String, Object> mapy2 = new HashMap<>();
		
		for(Map<String, Object> map: list2017){
			xlist.add(map.get("month").toString());
		}
		
		for(int i=0;i<list2017.size();i++){
			y1.add(list2017.get(i).get("indata").toString());
			y2.add(list2016.get(i).get("indata").toString());
		}
		mapy1.put("name", "今年");
		
		mapy1.put("data", y1);
		
		mapy2.put("name", "去年");
		
		mapy2.put("data", y2);
		

		List<Object> y=new ArrayList<>();
		y.add(mapy1);
		y.add(mapy2);

		
		Map<String, Object> map = new HashMap<>();
		map.put("x", xlist);
		map.put("y", y);
		
		return ApiR.ok().put("data", map);
	}
	
	/**
	 *进口今年与去年走势对比
	 */
	@AuthIgnore
	@GetMapping("/outyear")
	public ApiR outyear(HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		List<Map<String, Object>> list2017 = foreginManagementService.inyear("2017");
		List<Map<String, Object>> list2016 = foreginManagementService.inyear("2016");
	
		
		List<String> xlist=new ArrayList<>();
		List<String> y1=new ArrayList<>();
		List<String> y2=new ArrayList<>();
		Map<String, Object> mapy1 = new HashMap<>();
		Map<String, Object> mapy2 = new HashMap<>();
		
		for(Map<String, Object> map: list2017){
			xlist.add(map.get("month").toString());
		}
		
		for(int i=0;i<list2017.size();i++){
			y1.add(list2017.get(i).get("outdata").toString());
			y2.add(list2016.get(i).get("outdata").toString());
		}
		mapy1.put("name", "今年");
		
		mapy1.put("data", y1);
		
		mapy2.put("name", "去年");
		
		mapy2.put("data", y2);
		

		List<Object> y=new ArrayList<>();
		y.add(mapy1);
		y.add(mapy2);

		
		Map<String, Object> map = new HashMap<>();
		map.put("x", xlist);
		map.put("y", y);
		
		return ApiR.ok().put("data", map);
	}
	
	/**
	 * 2.5.5.4 本地交易量走势
	 */
	/**
	 *进口今年与去年走势对比
	 */
	@AuthIgnore
	@GetMapping("/btransaction")
	public ApiR btransaction(String time,HttpServletResponse response) {
		
		
		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		
		if(time.equals("quarter") || time==null){
			
		}else{
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		
		List<Map<String, Object>> list2017 = foreginManagementService.inyear("2017");
		List<Map<String, Object>> list2016 = foreginManagementService.inyear("2016");
	
		
		List<String> xlist=new ArrayList<>();
		List<String> y1=new ArrayList<>();
		List<String> y2=new ArrayList<>();
		Map<String, Object> mapy1 = new HashMap<>();
		Map<String, Object> mapy2 = new HashMap<>();
		
		for(Map<String, Object> map: list2017){
			xlist.add(map.get("month").toString());
		}
		
		for(int i=0;i<list2017.size();i++){
			y1.add(list2017.get(i).get("outdata").toString());
			y2.add(list2016.get(i).get("outdata").toString());
		}
		mapy1.put("name", "今年");
		
		mapy1.put("data", y1);
		
		mapy2.put("name", "去年");
		
		mapy2.put("data", y2);
		

		List<Object> y=new ArrayList<>();
		y.add(mapy1);
		y.add(mapy2);

		
		Map<String, Object> map = new HashMap<>();
		map.put("x", xlist);
		map.put("y", y);
		
		
		
		List<Map<String, Object>> list = foreginManagementService.queryInandout("5");
		
		return ApiR.ok().put("line", map).put("pie", list);
	}
	
	/**
	 * 2.5.5.4国际交易量走势
	 */
	/**
	 *进口今年与去年走势对比
	 */
	@AuthIgnore
	@GetMapping("/gjtransaction")
	public ApiR gjransaction(String time,HttpServletResponse response) {
		
		
		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		
		if(time.equals("quarter") || time==null){
			
		}else{
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		
		List<Map<String, Object>> list2017 = foreginManagementService.inyear("2017");
		List<Map<String, Object>> list2016 = foreginManagementService.inyear("2016");
	
		
		List<String> xlist=new ArrayList<>();
		List<String> y1=new ArrayList<>();
		List<String> y2=new ArrayList<>();
		Map<String, Object> mapy1 = new HashMap<>();
		Map<String, Object> mapy2 = new HashMap<>();
		
		for(Map<String, Object> map: list2017){
			xlist.add(map.get("month").toString());
		}
		
		for(int i=0;i<list2017.size();i++){
			y1.add(list2017.get(i).get("outdata").toString());
			y2.add(list2016.get(i).get("outdata").toString());
		}
		mapy1.put("name", "今年");
		
		mapy1.put("data", y1);
		
		mapy2.put("name", "去年");
		
		mapy2.put("data", y2);
		

		List<Object> y=new ArrayList<>();
		y.add(mapy1);
		y.add(mapy2);

		
		Map<String, Object> map = new HashMap<>();
		map.put("x", xlist);
		map.put("y", y);
		
		
		
		List<Map<String, Object>> list = foreginManagementService.queryInandout("5");
		
		return ApiR.ok().put("line", map).put("pie", list);
	}
	/**
	 * 2.5.5.4 国内交易量走势
	 */
	/**
	 *进口今年与去年走势对比
	 */
	@AuthIgnore
	@GetMapping("/gtransaction")
	public ApiR gransaction(String type,String time,HttpServletResponse response) {
		
		
		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		
		if(time.equals("quarter") || time==null){
			
		}else{
			return ApiR.ok().put("data",new ArrayList<>());
		}
		
		
		List<Map<String, Object>> list2017 = foreginManagementService.inyear("2017");
		List<Map<String, Object>> list2016 = foreginManagementService.inyear("2016");
	
		
		List<String> xlist=new ArrayList<>();
		List<String> y1=new ArrayList<>();
		List<String> y2=new ArrayList<>();
		Map<String, Object> mapy1 = new HashMap<>();
		Map<String, Object> mapy2 = new HashMap<>();
		
		for(Map<String, Object> map: list2017){
			xlist.add(map.get("month").toString());
		}
		
		for(int i=0;i<list2017.size();i++){
			y1.add(list2017.get(i).get("outdata").toString());
			y2.add(list2016.get(i).get("outdata").toString());
		}
		mapy1.put("name", "今年");
		
		mapy1.put("data", y1);
		
		mapy2.put("name", "去年");
		
		mapy2.put("data", y2);
		

		List<Object> y=new ArrayList<>();
		y.add(mapy1);
		y.add(mapy2);

		
		Map<String, Object> map = new HashMap<>();
		map.put("x", xlist);
		map.put("y", y);
		
		
		
		List<Map<String, Object>> list = foreginManagementService.queryInandout("5");
		
		return ApiR.ok().put("line", map).put("pie", list);
	}
	
	
	
	
	
	/**
	 *订单量走势
	 */
	@AuthIgnore
	@GetMapping("/orderlist")
	public ApiR orderlist(HttpServletResponse response) {
		

		// 允许跨域
		response.setHeader("Access-Control-Allow-Origin", "*");
		List<Map<String, Object>> list2017 = foreginManagementService.inyear("2017");
		List<Map<String, Object>> list2016 = foreginManagementService.inyear("2016");
	
		
		List<String> xlist=new ArrayList<>();
		List<String> y1=new ArrayList<>();
		List<String> y2=new ArrayList<>();
		Map<String, Object> mapy1 = new HashMap<>();
		Map<String, Object> mapy2 = new HashMap<>();
		
		for(Map<String, Object> map: list2017){
			xlist.add(map.get("month").toString());
		}
		
		for(int i=0;i<list2017.size();i++){
			y1.add(list2017.get(i).get("outdata").toString());
			y2.add(list2017.get(i).get("indata").toString());
		}
		mapy1.put("name", "出口");
		
		mapy1.put("data", y1);
		
		mapy2.put("name", "进口");
		
		mapy2.put("data", y2);
		

		List<Object> y=new ArrayList<>();
		y.add(mapy1);
		y.add(mapy2);

		
		Map<String, Object> map = new HashMap<>();
		map.put("x", xlist);
		map.put("y", y);
		
		return ApiR.ok().put("data", map);
	}
	
	/**
	 *	2.5.5.9 进口产品占比
	 */
	@AuthIgnore
	@GetMapping("/importproportion")
	public ApiR importproportion(HttpServletResponse response) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		
		List<Map<String, Object>> list = foreginManagementService.queryInandout("5");
		
		return ApiR.ok().put("data", list);
	}
	
	/**
	 *	2.5.5.9 出口产品占比
	 */
	@AuthIgnore
	@GetMapping("/exportsproportion")
	public ApiR exportsproportion(HttpServletResponse response) {
		response.setHeader("Access-Control-Allow-Origin", "*");
		
		List<Map<String, Object>> list = foreginManagementService.queryInandout("6");
		
		return ApiR.ok().put("data", list);
	}
	
	
}
